Generates all permutations of a set in-place using the Heap Algorithm to minimize memory overhead and avoid stack overflow.